<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    


<head>
	<script type="text/javascript">
		$(function(){
			init();
		});
		
		function init(){
			$('#t-dg').datagrid({
				loadMsg:''
			});
		}
		

		var actionUrl;
		function newItem(){
			$('#dlg').dialog('setTitle', '新增系统配置').dialog('open');
			$('#myform').form('clear');
			actionUrl = '<c:url value="/system/Config/saveConfigs"/>';
		}
		function editItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				$('#myform').form('load', row);
				$('#dlg').dialog('setTitle', '修改系统配置').dialog('open');
				actionUrl = '<c:url value="/system/Config/updateConfigs"/>?id=' + row.id;
			}
		}
		
		function deleteItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				
				$.messager.confirm('删除确认', '是否确定要删除选择系统配置?', function(r){
						if (r){
				$.ajax({
					url:'<c:url value="/system/Config/destroyConfigs"/>?id=' + row.id,
					type:'post',
					success:function(){
						$('#t-dg').datagrid('reload');
					}
				});
			}});
				
			}
		}
		
		function saveItem(){
			$('#myform').form('submit', {
				url:actionUrl,
				onSubmit:function(){
					return $('#myform').form('validate');
				},
				success:function(data){
					var data = eval('('+data+')');
					if (data.success){
						$('#dlg').dialog('close');
						$('#t-dg').datagrid('reload');
					} else {
						$.messager.show({
							title:'保存失败',
							msg:'<pre>'+data.msg+'</pre>'
						});
					}
				}
			});
		}
		function doQuery(value){
			$('#t-dg').datagrid('load', {
				q: value
			});
		}
	</script>
</head>
<body>
	<div class="easyui-layout" fit="true">
		<div region="north" border="false" style="height:40px;padding:5px;overflow:hidden;" >
		<div style="padding-top:3px;float:left">
			<input class="easyui-searchbox" prompt="按编号|名称|类型进行查询" searcher="doQuery" style="width:300px"></input>
			</div>
			<div style="float:left">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增系统配置</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">修改系统配置</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteItem()">删除系统配置</a>
			</div>			
		</div>
		
		
		<div region="center" border="true">
			<table id="t-dg" style="display:none;"
					url="<c:url value='/system/Config/getConfigsItems'/>"
					singleSelect="true" rownumbers="true" pagination="true"
					border="false" fit="true" fitColumns="true">
				<thead>
					<tr>
						<th field="cfgcode" width="80" sortable="true">配置编号</th>
<th field="cfgkeyname" width="100" sortable="true">配置名称</th>
<th field="cfgtype" width="100" sortable="true">配置类型</th>
<th field="cfgkeyvalue" width="150" sortable="false">配置值</th>
<th field="cfgremark" width="150" sortable="false">配置说明</th>

					</tr>
				</thead>
			</table>
		</div>
	</div>
	
<div id="dlg" style="width:400px;
<c:if test="${cfgs['menulayout'] == 'default'}">
height:310px; 
</c:if>
<c:if test="${cfgs['menulayout'] == 'topbottom'}">
height:250px; 
</c:if>
"
			class="easyui-dialog" closed="true" modal="true" buttons="#dlg-buttons">
		<div style="padding:10px">
			<div style="float:left">
				<form id="myform" method="post" style="margin:0;padding:0">
					<table>
						<tr>
<td style="width:80px">配置编号</td>
<td><input type="text" class="easyui-validatebox e-input" id="cfgcode" name="cfgcode" style="width:250px;" required="true" editable="true"></input></td>
</tr>	
<tr>
<td style="width:80px">配置名称</td>
<td><input type="text" class="easyui-validatebox e-input" id="cfgkeyname" name="cfgkeyname" style="width:250px;" required="true" editable="true"></input></td>
</tr>	
<tr>
<tr>
<td style="width:80px">配置类型</td>
<td><input type="text" class="easyui-validatebox e-input" id="cfgtype" name="cfgtype" style="width:250px;" required="true" editable="true"></input></td>
</tr>	
<tr>
<td style="width:80px">配置值</td>
<td><textarea type="text" class="easyui-validatebox e-input" id="cfgkeyvalue" name="cfgkeyvalue" style="width:250px;height:50px" required="true"></textarea></td>
</tr>	
<tr>
<td style="width:80px">配置说明</td>
<td><textarea type="text" class="easyui-validatebox e-input" id="cfgremark" name="cfgremark" style="width:250px;height:50px"></textarea></td>
</tr>	
								
					</table>
				</form>
			</div>			
			<div style="clear:both"></div>
		</div>
		<div id="dlg-buttons" style="text-align:center;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="saveItem()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
</div>

	

</body>
